home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / totsrc.zip / EXTIO.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-11  |  3KB  |  135 lines

  1. Unit ExtIO;
  2. {Illustrates how you can extend the Toolkit IO objects. A boolean
  3.  field is created.}
  4.  
  5. {$I TOTFLAGS.INC}
  6. INTERFACE
  7.  
  8. uses DOS, CRT, totFAST, totIO1, totSTR, totInput;
  9.  
  10. TYPE
  11. BooleanIOOBJ = object (VisibleIOOBJ)
  12.    OnString: StringBut;
  13.    OffString: StringBut;
  14.    vInput: boolean;
  15.    {methods...}
  16.    constructor Init(X,Y:byte; Yes,No:stringbut);
  17.    function    GetValue: boolean;
  18.    procedure   SetValue(On:boolean);
  19.    procedure   Activate;
  20.    procedure   Display(Status:tStatus);                  VIRTUAL;
  21.    function    Select(K:word; X,Y:byte):tAction;         VIRTUAL;
  22.    function    ProcessKey(InKey:word;X,Y:byte):tAction;  VIRTUAL;
  23.    function    Suspend:boolean;                          VIRTUAL;
  24.    destructor  Done;                                     VIRTUAL;
  25. end; {BooleanIOOBJ}
  26.  
  27. IMPLEMENTATION
  28.  
  29. constructor BooleanIOOBJ.Init(X,Y:byte; Yes,No:stringbut);
  30. {}
  31. var L:byte;
  32. begin
  33.    VisibleIOOBJ.Init;
  34.    OnString := Yes;
  35.    OffString := No;
  36.    L := length(OnString);
  37.    if L < length(OffString) then
  38.       L := length(OffString);
  39.    with vBoundary do
  40.    begin
  41.       X1 := X;
  42.       X2 := X + pred(L);
  43.       Y1 := Y;
  44.       Y2 := Y;
  45.    end;
  46.    vInput := true;
  47. end; {BooleanIOOBJ.Init}
  48.  
  49. function BooleanIOOBJ.GetValue: boolean;
  50. {}
  51. begin
  52.    GetValue := vInput;
  53. end; {BooleanIOOBJ.GetValue}
  54.  
  55. procedure BooleanIOOBJ.SetValue(On:boolean);
  56. {}
  57. begin
  58.    vInput := On;
  59. end; {BooleanIOOBJ.SetValue}
  60.  
  61. procedure BooleanIOOBJ.Display(Status:tStatus);                  
  62. {}
  63. var Att: byte;
  64. begin
  65.    case Status of
  66.       HiStatus: Att := IOTOT^.FieldCol(2);
  67.       Norm:     Att := IOTOT^.FieldCol(1);
  68.       Off:      Att := IOTOT^.FieldCol(4);
  69.    end; {case}
  70.    with vBoundary do
  71.       if vInput then
  72.          Screen.WriteAT(X1,Y1,Att,padleft(OnString,succ(X2-X1),' '))
  73.       else
  74.          Screen.WriteAT(X1,Y1,Att,padleft(OffString,succ(X2-X1),' '));
  75. end; {BooleanIOOBJ.Display}
  76.  
  77. function BooleanIOOBJ.Select(K:word; X,Y:byte):tAction;         
  78. {}
  79. begin
  80.    Display(HiStatus);
  81.    WriteLabel(HiStatus);
  82.    WriteMessage;
  83.    Screen.GotoXY(vBoundary.X1,vBoundary.Y1);
  84.    Select := none;
  85. end; {BooleanIOOBJ.Select}
  86.  
  87. function BooleanIOOBJ.ProcessKey(InKey:word;X,Y:byte):tAction;  
  88. {}
  89. begin
  90.    if (InKey = 513) 
  91.    or (InKey = 32) 
  92.    or (inKey = 328) 
  93.    or (InKey = 336) then
  94.    begin
  95.       vInput := not vInput;
  96.       Display(HiStatus);
  97.    end;
  98.    if InKey = 513 then {absorb mouse}
  99.       delay(100);
  100.    if (InKey = 13) then
  101.       ProcessKey := Enter
  102.    else
  103.       ProcessKey := None;
  104. end; {BooleanIOOBJ.ProcessKey}
  105.  
  106. procedure BooleanIOOBJ.Activate;
  107. {}
  108. var
  109.    Action: tAction;
  110. begin
  111.    Action := Select(0,0,0);
  112.    Display(HiStatus);
  113.    WriteLabel(HiStatus);
  114.    with Key do 
  115.    begin
  116.       repeat
  117.          GetInput;
  118.          Action := ProcessKey(LastKey,LastX,LastY);
  119.       until ((LastKey = 324) or (LastKey = 13)) and Suspend;
  120.    end;
  121. end; {BooleanIOOBJ.Activate}
  122.  
  123. function BooleanIOOBJ.Suspend:boolean;                        
  124. {}
  125. begin
  126.    Suspend := VisibleIOOBJ.Suspend;
  127. end; {BooleanIOOBJ.Suspend}
  128.  
  129. destructor BooleanIOOBJ.Done;                                     
  130. {}
  131. begin
  132.    VisibleIOOBJ.Done;
  133. end; {BooleanIOOBJ.Done}
  134.  
  135. end.